home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 14 / Example 14.1 / intpoint.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-05-12  |  1.3 KB  |  33 lines

  1. #ifndef _INTPOINT
  2. #define _INTPOINT
  3.  
  4. #include <d3dx9.h>
  5. #include <math.h>
  6. #include "debug.h"
  7.  
  8. class INTPOINT{
  9.     public:
  10.         INTPOINT(){x = y = 0;}
  11.         INTPOINT(int _x, int _y){Set(_x,_y);}
  12.  
  13.         void operator=(const POINT rhs){x = rhs.x;y = rhs.y;}
  14.         bool operator==(const INTPOINT rhs){return rhs.x == x && rhs.y == y;}
  15.         bool operator!=(const INTPOINT rhs){return rhs.x != x || rhs.y != y;}
  16.         void operator+=(const INTPOINT rhs){x += rhs.x; y += rhs.y;}
  17.         void operator/=(const int rhs){x /= rhs; y /= rhs;}
  18.         INTPOINT operator/(const INTPOINT rhs){return INTPOINT(x / rhs.x, y / rhs.y);}
  19.         INTPOINT operator/(const int d){return INTPOINT(x / d, y / d);}
  20.         INTPOINT operator-(const INTPOINT &rhs){return INTPOINT(x - rhs.x, y - rhs.y);}
  21.         INTPOINT operator+(const INTPOINT &rhs){return INTPOINT(x + rhs.x, y + rhs.y);}
  22.         INTPOINT operator-(const int &rhs){return INTPOINT(x - rhs, y - rhs);}
  23.         INTPOINT operator+(const int &rhs){return INTPOINT(x + rhs, y + rhs);}
  24.  
  25.         float Distance(INTPOINT p){return sqrtf((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));}
  26.         bool inRect(RECT r){if(x < r.left || x > r.right || y < r.top || y > r.bottom)return false;else return true;}
  27.         void Set(int _x, int _y){x = _x; y = _y;}
  28.         void SetRandom(RECT r){x = rand()%(r.right - r.left) + r.left; y = rand()%(r.bottom - r.top) + r.top;}
  29.  
  30.         int x,y;
  31. };
  32.  
  33. #endif